package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.system.domain.IOTData;
import com.ruoyi.system.mapper.IOTDataMapper;
import com.ruoyi.system.service.ISIOTService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wang
 * @version 1.0
 * @data 2024/3/26 下午 8:02
 * @desc 描述信息
 */
@Service
public class IOTDataServiceImpl implements ISIOTService {
    @Resource
    private IOTDataMapper iotDataMapper;
    @Override
    public List<IOTData> getListByProperties(String properties,Long page,Long pageSize) {
        QueryWrapper<IOTData> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("properties",properties);
        queryWrapper.orderByDesc("create_time");
        Page page1 = Page.of(page - 1,(page) *pageSize );
        Page page11 = iotDataMapper.selectPage(page1, queryWrapper);
        List<IOTData> records = page11.getRecords();
        return records;
    }

    @Override
    public IOTData getOneData(String properties) {
        QueryWrapper<IOTData> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("properties",properties);
        queryWrapper.orderByDesc("create_time");
        Page page1 = Page.of(0,1);

        Page page11 = iotDataMapper.selectPage(page1, queryWrapper);
        List<IOTData> records = page11.getRecords();
        if (records.size() > 0){
            return records.get(0);
        }
        return null;
    }

    @Override
    public List<IOTData> queryProperty() {
        QueryWrapper  queryWrapper = new QueryWrapper();
        // queryWrapper.o
        List<IOTData> iotData = iotDataMapper.selectFirstRecordForEachGroupUsingNativeSql();
        return iotData;
    }
}
